package com.computergames.server.protocol;

import com.computergames.server.message.chessMessage.AbstractChessMessage;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;

public class AbstractChessMessageTypeAdapterFactory implements TypeAdapterFactory {
    @Override
    public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
        if (!AbstractChessMessage.class.isAssignableFrom(type.getRawType())) {
            return null; // 不处理非 AbstractChessMessage 类型
        }
        // 确保 AbstractChessMessageTypeAdapter 能够访问到 Gson 实例
        return (TypeAdapter<T>) new AbstractChessMessageTypeAdapter(gson);
    }
}
